﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ZK.Common;

namespace ZK.YHP_TransManage.Test
{
    public partial class 红外测试 : Form
    {

        /// <summary>
        /// 红外数据
        /// </summary>
        private int InfraredGratingDate;
        HardWareBLL.InfraredGratingBLL infraredGratingBLL;

        public 红外测试()
        {
            InitializeComponent();
            var ports = SerialPort.GetPortNames();
            comboBox1.DataSource = ports;
        }




        /// <summary>
        /// 红外光栅委托
        /// </summary>
        /// <param name="data"></param>
        private void InfraredGratingEvent1(int data)
        {
            //
            InfraredGratingDate = data;
            PageShow(data.ToString());
        }

        string tempstr = "";

        private void PageShow(string str)
        {
            //lock (obj)
            //{
            this.Invoke(new Action(() =>
            {
                if (tempstr != str)
                {
                    textBox1.AppendText("--" + str + "\n");
                    tempstr = str;
                }

            }));
            // }

        }
        /// <summary>
        /// open
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            bool res = infraredGratingBLL.Open();
            if (res)
            {
                Common.ShowBlackBox.WriteLine("1 open infrared success");
            }else
                Common.ShowBlackBox.WriteLine("1 open infrared fail");

        }
        /// <summary>
        /// close
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            infraredGratingBLL.Close();
            Common.ShowBlackBox.WriteLine("1 close infrared success");
        }
        /// <summary>
        /// init
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {
            var hM = new HaredWareCommonM()
            {
                PortName = comboBox1.SelectedItem.ToString()
               // PortName = "com2"
            };
            IConfig.GetSetInfrared = hM;
            DelegateHelper.InfraredGratingEvent += InfraredGratingEvent1;//红外光栅委托
            infraredGratingBLL = new HardWareBLL.InfraredGratingBLL();
            Common.ShowBlackBox.WriteLine("1 init infrared success");
        }
    }
}
